package com.fuego.creditsystemcommodity.controller;

import com.fuego.creditsystemcommodity.service.IRoomInfoService;
import com.fuego.creditsystemcommodity.service.IRoomService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.example.dto.Result;
import org.example.entity.Room;
import org.springframework.web.bind.annotation.*;




@RestController
@RequestMapping("/room")
public class RoomController {

    @Resource
    private IRoomService roomService;

    @Resource
    private IRoomInfoService roomInfoService;


    @PostMapping
    public Result addRoom(@RequestBody Room room) {
        roomService.save(room);
        return Result.ok(room.getId());
    }


    @PostMapping("roomInfo")
    public Result addRoomInfo(@RequestBody Room room) {
        roomService.addRoomInfo(room);
        return Result.ok(room.getId());
    }


    @GetMapping("/list/{hotelId}")
    public Result queryRoomOfHotel(@PathVariable("hotelId") Long hotelId) {
        return roomService.queryRoomOfHotel(hotelId);
    }

    @GetMapping("/list/allRoom")
    public Result queryAllRoom() {
        return roomService.queryAllRoom();
    }


    @GetMapping("/list/pageRoom")
    public Result pageRoom(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "20") Integer pageSize
    ) {

        return roomService.pageRoom(page, pageSize);
    }

    @GetMapping("/room/{roomId}")
    public Result queryRoomById(@PathVariable("roomId") Long roomId) {

        return roomService.queryRoomById(roomId);
    }

    @GetMapping("/roomInfo/{roomId}")
    public Result queryRoomInfoById(@PathVariable("roomId") Long roomId) {

        return roomInfoService.queryRoomInfoById(roomId);
    }


    @GetMapping("/search/{roomName}")
    public Result searchGood(@PathVariable("roomName") String roomName) {

        return roomService.searchRoom(roomName);
    }
}

